package routers

import (
	"fastgin/api"
	"fastgin/api/user_api"
	"fastgin/middleware"
	"fastgin/models"

	"github.com/gin-gonic/gin"
)

func UserRouter(g *gin.RouterGroup) {
	app := api.App.UserApi
	g.POST("users/login", middleware.LimitMiddleware(2), middleware.BindJson[user_api.LoginRequest], app.LoginView)
	g.GET("users/list", middleware.LimitMiddleware(2), middleware.AdminAuthMiddleware, middleware.BindQuery[models.PageInfo], app.UserListView)
	g.POST("users/logout", middleware.AuthMiddleware, app.LogoutView)
	// g.POST("users/create", middleware.LimitMiddleware(2), middleware.BindJson[user_api.CreateUserRequest], app.CreateUserView)
	g.POST("users/create", middleware.LimitMiddleware(2), middleware.AdminAuthMiddleware, middleware.BindJson[user_api.CreateUserRequest], app.CreateUserView) //这两种两种都可以
	g.DELETE("users/delete", middleware.LimitMiddleware(2), middleware.AdminAuthMiddleware, middleware.BindJson[models.IDList], app.DelUserView)
	g.PUT("users/update_pwd", middleware.LimitMiddleware(2), middleware.AdminAuthMiddleware, middleware.BindJson[user_api.UpdatePwdRequest], app.UpdatePwdView)
	g.PUT("users/update_role", middleware.LimitMiddleware(2), middleware.AdminAuthMiddleware, middleware.BindJson[models.IDList], app.UpdateRoleView)
}
